<template>
  <div>
    <s-table row-key="id" size="default" :columns="columns" :data="loadData" ref="table">
      <span slot="baseinfo" slot-scope="text, record">
        <img style="width: 45px; heigth: 45px;border-radius:5px;margin-right:10px" :src="record.avatar_url" />
        <span>{{ record.nickname }} </span>
      </span>
      <span slot="time" slot-scope="text, record">
        <span>{{ record.created_at | timeFormat }}</span>
      </span>
      <span slot="type" slot-scope="text, record">
        <span v-if="record.log_type == 1">收入</span>
        <span v-else>支出</span>
      </span>
    </s-table>
  </div>
</template>

<script>
import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN'
import moment from 'moment'
import { STable } from '@/components'
import { getRechargeList } from '@/api/recharge'

const columns = [
  {
    title: '用户ID',
    dataIndex: 'user_id',
    width: 100,
  },
  {
    title: '用户信息',
    dataIndex: 'nickname',
    scopedSlots: { customRender: 'baseinfo' },
    width: 200,
  },
  {
    title: '类型',
    dataIndex: 'log_type',
    scopedSlots: { customRender: 'type' },
  },
  {
    title: '充值/扣减数额',
    dataIndex: 'amount',
  },
  {
    title: '说明',
    dataIndex: 'desc',
    width: 400,
  },
  {
    title: '更改前',
    dataIndex: 'before',
  },
  {
    title: '更改后',
    dataIndex: 'after',
  },
  {
    title: '操作者',
    dataIndex: 'operator',
  },
  {
    title: '时间',
    dataIndex: 'created_at',
    scopedSlots: { customRender: 'time' },
  },
]

export default {
  name: 'UserIntegralRecord',
  components: {
    STable,
  },
  props: {
    queryParam: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      selectDate: null,
      locale: zhCN,
      ranges: {
        一月内: () => [moment().startOf('day').subtract(1, 'month'), moment()],
        昨天: () => [moment().startOf('day').subtract(1, 'days'), moment().endOf('day').subtract(1, 'days')],
        最近一周: () => [moment().startOf('day').subtract(1, 'weeks'), moment()],
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      form: this.$form.createForm(this),
      // 表头
      columns,
      // 权限树
      permissionTree: [],
      modalLoading: false,
      defaultCheckedKeys: [],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        Object.assign(parameter, this.queryParam, { type: 1 })
        return getRechargeList(parameter).then((res) => {
          return res.data
        })
      },
    }
  },
  created() {},
  methods: {
    resetSearchForm() {
      this.queryParam = {
        dateStart: moment(new Date()),
        dateEnd: moment(new Date()),
      }
    },
    moment,
    // 选中日期事件
    calendarChange(date, dateString) {
      // if (date.length <= 1) {
      //   // 选中开始日期事件，设置结束日期必须大于1天
      //   this.selectDate = date[0].add(1, 'days')
      // } else {
      //   this.selectDate = null
      // }
      this.selectDate = date[0]
    },
    // 选择后的事件
    onChange(date, dateString) {
      this.queryParam.dateStart = dateString[0]
      this.queryParam.dateEnd = dateString[1]
    },
  },
}
</script>
